package y24.m4;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.Stack;

public class Test6 {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();//输入节点数量
        List<Integer> n = new ArrayList<>();
        List<Stack<Integer>> num = new ArrayList<>(N-1);
        for (int i = 0; i < N-1; i++) {
            Stack<Integer> stack = new Stack<>();
            num.add(stack);

        }
        String p = scan.next();
        while(p !=null){
            if (!p.equals("query")){
                int val = scan.nextInt();
                switch (p){
                    case "add":
                        n.add(val);
                        break;
                    case "sync":
                        int x = num.get(val-1).size();
                        if (x < n.size()){
                            num.get(val-1).add(n.get(x));
                        }
                        break;
                    default:
                        return;
                }
            }else {
                System.out.println(query(num));
            }

            p = scan.next();
        }
    }
    public static int query(List<Stack<Integer>> list){
        int num = 100000;
        int N = list.size();
        for (int i = 0; i < N; i++) {
            num = Math.min(num,list.get(i).size());
        }
        return num;
    }
}
